#include "audio_sound_3d.h"

using namespace krryn;
using namespace krryn::audio;

sound_3d::sound_3d(sound::ptr a_Input, audio::listener::ptr a_Listener, const vector3f &a_Position)
 : m_Input(a_Input), 
   m_Listener(a_Listener), 
   m_Position(a_Position)
{
}

void sound_3d::set_volume(float a_Volume){
	m_Input->set_volume(a_Volume);
}

float sound_3d::volume(){
	return m_Input->volume();
}

void sound_3d::loop(bool a_Loop){
	m_Input->loop(a_Loop);
}

void sound_3d::set_position(const vector3f &a_Position){
	m_Position = a_Position;
}

vector3f sound_3d::position(){
	return m_Position;
}

sample::ptr sound_3d::next(int a_MilliSeconds){
	sample::ptr l_Sample = m_Input->next(a_MilliSeconds);

	if(l_Sample){
		l_Sample->set_pan(m_Listener->pan_for_position(m_Position));

		// replace this by some attenuation formula
		l_Sample->set_volume(m_Input->volume());
	}

	return l_Sample;
}

bool sound_3d::more(){
	return m_Input->more();
}

void sound_3d::reset(){
	return m_Input->reset();
}
